package com.example.com.hupu.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.example.com.hupu.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 闪屏页展示几秒，然后才跳转到Main
 */
public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.tv_jump)
    TextView tvJump;
    private Handler mHandler = new Handler();
    private boolean mHasDone;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                jump2Main();
            }
        }, 2000);
    }

    private void jump2Main() {
        if (mHasDone) {
            return;
        }
        mHasDone = true;
        Intent intent = new Intent(SplashActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 删除所有Handler相关的Msg和回调函数
        mHandler.removeCallbacksAndMessages(null);
    }

    @OnClick(R.id.tv_jump)
    public void onClick() {
        jump2Main();
    }
}
